package com.songlanyun.common.enums;


import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.songlanyun.common.drive.IntegerEnum;
import com.songlanyun.common.utils.MsgTemEnum;

import java.util.Objects;

/**
 * 充值订单相关枚举
 */
public class RefillOrderConstant {

    /**
     * 0未支付，1支付已提交,2支付成功，但业务发生异常需要发起退款，3支付成功，但业务发生异常自动退款成功，4支付成功，但业务发生异常自动退款失败，5支付成功，但微信返回的金额与实际支付的金额不相等,6支付失败，7已支付(已支付成功)
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum PaymentStatus implements IntegerEnum<Integer> {

        /**
         * 未支付
         */
        NO_PAY(0, "未支付"),

        /**
         * 支付已提交
         */
        ALREADY_SUBMIT(1, "支付已提交"),

        /**
         * 支付成功，但业务发生异常需要发起退款
         */
        SUCCESS_BUSINESS_ERROR_LAUNCH_REFUND(2, "支付成功，但业务发生异常需要发起退款"),
        /**
         * 支付成功，但业务发生异常自动退款成功
         */
        SUCCESS_BUSINESS_ERROR_REFUND_SUCCESS(3, "支付成功，但业务发生异常自动退款成功"),
        /**
         * 支付成功，但业务发生异常自动退款失败
         */
        SUCCESS_BUSINESS_ERROR_REFUND_FAIL(4, "支付成功，但业务发生异常自动退款失败"),
        /**
         * 支付成功，但微信返回的金额与实际支付的金额不相等
         */
        SUCCESS_BUSINESS_ERROR_AMOUNT_UNEQUAL(5, "支付成功，但微信返回的金额与实际支付的金额不相等"),
        /**
         * 支付失败
         */
        FAIL(6, "支付失败"),

        /**
         * 已支付(已支付成功)
         */
        SUCCESS(7, "已支付(已支付成功)");


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        PaymentStatus(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static RefillOrderConstant.PaymentStatus getByCode(int code) {
            for (RefillOrderConstant.PaymentStatus value : RefillOrderConstant.PaymentStatus.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }


    /**
     * 0未关闭，1手动关闭，2过期支付关闭
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum CloseStatus implements IntegerEnum<Integer> {

        NOT_CLOSE(0, "未关闭"),

        MANUAL_LOCK(1, "手动关闭"),

        PAY_CLOSE(2, "过期支付关闭"),
        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        CloseStatus(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static RefillOrderConstant.CloseStatus getByCode(int code) {
            for (RefillOrderConstant.CloseStatus value : RefillOrderConstant.CloseStatus.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 交易状态（0已下单,待支付，1交易结束
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum TransactionStatus implements IntegerEnum<Integer> {

        WAIT_PAYMENT(0, "已下单,待支付"),

        CLOSE(1, "交易完成"),
        ;


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        TransactionStatus(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static RefillOrderConstant.TransactionStatus getByCode(int code) {
            for (RefillOrderConstant.TransactionStatus value : RefillOrderConstant.TransactionStatus.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

    /**
     * 支付方式（0余额，1微信，2支付宝）
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum PayMode implements IntegerEnum<Integer> {
        //0余额，1微信，2支付宝
        BALANCE(0, "余额"),
        WE_CHAT(1, "微信"),
        ALIPAY(2, "支付宝");


        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        PayMode(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static OrderConstant.PayMode getByCode(int code) {
            for (OrderConstant.PayMode value : OrderConstant.PayMode.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }
}
